package com.itheima.reggie.config;

import com.itheima.reggie.common.JacksonObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Slf4j
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    /**
     * 扩展Mvc中json的消息转换器
     * @param converters
     */
    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        log.info("扩展消息转换器....");
        // 创建消息转换器
        MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
        // 将我们扩展的转换器替换掉原来的转换器
        mappingJackson2HttpMessageConverter.setObjectMapper(new JacksonObjectMapper());
        // 将消息转换器追加到Mvc容器中
        converters.add(0,mappingJackson2HttpMessageConverter);
    }


  /*  @Autowired
    private LoginInterceptor loginInterceptor;*/

    /**
     * 配置登陆拦截器
     * @param registry
     */
    /*@Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("登陆拦截器已经启用....");
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**");
    }*/
}
